//正解
#include <iostream>

using namespace std;

int n;

int main()
{
	cin >> n;
	
	int cnt = 0;
	
	while (n)
	{
		if (n & 1) cnt ++ ;
//		cout << n << "==" << cnt << endl;
		n /= 2;
	}
	
	cout << cnt << endl;
	
	return 0;
}

//错解
#include <iostream>

using namespace std;

const int N = 40;

int s[N];

void init()
{
	s[0] = 1;
	
	for (int i = 1; i <= 30; i ++ ) s[i] = s[i - 1] * 2;
}

int main()
{
	int n;
	cin >> n;
	
	init();
	
	int l = 0, r = 30;
	
	while (l < r)
	{
		int mid = l + r >> 1;
		
		if (s[mid] >= n) r = mid;
		else l = mid + 1;
	}
	
//	cout << l << endl;
	
	cout << min(abs(s[r] - n), abs(n - s[r - 1])) + 1 << endl;
	
	return 0;
}